package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user")
@SuppressWarnings({"all"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

@Operation(summary = "根据用户ID查询用户基本信息")
	@GetMapping("/userInfo/getUserInfoVo/{userId}")
	public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId){
		UserInfoVo userInfoVo=userInfoService.getUserInfo(userId);
		return Result.ok(userInfoVo);
	}

@Operation(summary = "提交需要检查购买状态的声音ID列表,响应每个声音的购买状态")
	@PostMapping("/userInfo/userIsPaidTrack/{userId}/{albumId}")
	public Result<Map<Long,Integer>> userIsPaidTrack(
			@PathVariable Long userId,
			@PathVariable Long albumId,
			@RequestBody List<Long> needCheckPayStatusTrackIdList)
    {
         Map<Long,Integer> map=userInfoService.userIsPaidTrack(userId,albumId,needCheckPayStatusTrackIdList);
		 return Result.ok(map);
	}

@GuiGuLogin(required = false)
	@Operation(summary = "获取声音播放进度")
	@GetMapping("/userListenProcess/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId){
	Long userId = AuthContextHolder.getUserId();
	if(userId !=null){
		BigDecimal breakSecond=userInfoService.getTrackBreakSecond(userId,trackId);
		return Result.ok(breakSecond);
	}
	return Result.ok(BigDecimal.valueOf(0));
	}


	@GuiGuLogin(required = false)
	@Operation(summary = "更新声音播放进度")
	@PostMapping("/userListenProcess/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		Long userId = AuthContextHolder.getUserId();
		if(userId !=null){
			userInfoService.updateListenProcess(userId,userListenProcessVo);
		}
	return Result.ok();
	}



}

